home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2004 April / SGI IRIX 6.5 Applications 2004 April.iso / dist / mozilla.idb / var / netscape / mozilla / chrome / comm.jar.z / comm.jar / content / p3p / pageInfoOverlay.js < prev    next >
Text File  |  2003-11-11  |  7KB  |  232 lines

  1. /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is the Platform for Privacy Preferences.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 2002
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s): Samir Gehani <sgehani@netscape.com>
  23.  *                 Harish Dhurvasula <harishd@netscape.com>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the MPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the MPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. var gTopWin = null;
  40. var gTopDoc = null;
  41. var gIOService = null;
  42.  
  43. function initTopDocAndWin()
  44. {
  45.   if ("arguments" in window && window.arguments.length > 0 && 
  46.       window.arguments[0])
  47.   {
  48.     gTopWin = null;
  49.     gTopDoc = window.arguments[0];
  50.   }
  51.   else 
  52.   {
  53.     if ("gBrowser" in window.opener)
  54.       gTopWin = window.opener.gBrowser.contentWindow;
  55.     else
  56.       gTopWin = window.opener.frames[0];
  57.     gTopDoc = gTopWin.document;
  58.   }
  59. }
  60.  
  61. function initP3PTab()
  62. {
  63.   initTopDocAndWin();
  64.  
  65.   var mainLinkNode = document.getElementById("mainLink");
  66.   mainLinkNode.setAttribute("label", gTopDoc.location.href);
  67.   
  68.   // now select the main link
  69.   var tree = document.getElementById("linkList");
  70.   tree.treeBoxObject.selection.select(0);
  71.  
  72.   var linkTypes = 
  73.   [
  74.   //  Tag       Attr         List node ID
  75.     ["a",      "href",      "linkKids"],
  76.     ["applet", "code",      "appletKids"],
  77.     ["area",   "href",      "imageMapKids"],
  78.     ["form",   "action",    "formKids"], 
  79.     ["frame",  "src",       "frameKids"], 
  80.     ["iframe", "src",       "frameKids"],
  81.     ["img",    "src",       "imageKids"],
  82.     ["image",  "src",       "imageKids"],
  83.     ["link",   "href",      "externalDocKids"],
  84.     ["object", "codebase",  "objectKids"],
  85.      ["object", "data",      "objectKids"],
  86.     ["script", "src",       "scriptKids"]
  87.   ];
  88.  
  89.   var list, i, j;
  90.   var length = linkTypes.length;
  91.   for (i = 0; i < length; ++i)
  92.   {
  93.     list = getLinksFor(linkTypes[i][0], linkTypes[i][1], gTopWin, gTopDoc);
  94.     // now add list items under appropriate link type in the tree
  95.     var len = list.length;
  96.     for (j = 0; j < len; ++j)
  97.     {
  98.       addRow(linkTypes[i][2], list[j]);
  99.     }
  100.   }
  101. }
  102.  
  103. function makeURLAbsolute(url, base)
  104. {
  105.   if (url.indexOf(':') > -1)
  106.     return url;
  107.  
  108.   if (!gIOService) {
  109.     gIOService = 
  110.       Components.classes["@mozilla.org/network/io-service;1"].getService(nsIIOService);
  111.   }
  112.  
  113.   var baseURI = gIOService.newURI(base, null, null);
  114.  
  115.   return gIOService.newURI(baseURI.resolve(url), null, null).spec;
  116. }
  117.  
  118. function getLinksFor(aTagName, aAttrName, aWin, aDoc)
  119. {
  120.   var i, frame, list = new Array;
  121.  
  122.   // cycle through frames
  123.   if (aWin && aWin.frames.length > 0)
  124.   {
  125.     var length = aWin.frames.length;
  126.     for (i = 0; i < length; ++i)
  127.     {
  128.       frame = aWin.frames[i];
  129.       list = list.concat(getLinksFor(aTagName, aAttrName, 
  130.                                      frame, frame.document));
  131.     }
  132.   }
  133.  
  134.   // now look for tags in the leaf document
  135.   var elts = aDoc.getElementsByTagName(aTagName);
  136.   var length = elts.length;
  137.   for (i = 0; i < length; ++i)
  138.   {
  139.     var url = elts[i][aAttrName];
  140.     if (url) {
  141.       try {
  142.         // The user sees the links as absolute when mousing over.
  143.         // The link list does not show the base URL for the user,
  144.         // so this is the only way we can indicate where things
  145.         // really point to in the link list.
  146.         list.push(makeURLAbsolute(url, elts[i].baseURI));
  147.       } catch (e) {
  148.         // XXX Ignore for now, most likely bad URL, but could also be 
  149.         //     something really serious like out of memory.
  150.       }
  151.     }
  152.   }
  153.  
  154.   return list;
  155. }
  156.  
  157. function addRow(aRootID, aLabel)
  158. {
  159.   const kXULNS = 
  160.     "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  161.   var root = document.getElementById(aRootID);
  162.   var item = document.createElementNS(kXULNS, "treeitem");
  163.   root.appendChild(item);
  164.   var row = document.createElementNS(kXULNS, "treerow");
  165.   item.appendChild(row);
  166.   var cell = document.createElementNS(kXULNS, "treecell");
  167.   cell.setAttribute("label", aLabel);
  168.   row.appendChild(cell);
  169. }
  170.  
  171. function getSelectedURI()
  172. {
  173.   var URI = null;
  174.   var tree = document.getElementById("linkList");
  175.   var selectedItem = tree.contentView.getItemAtIndex(tree.currentIndex);
  176.   if (selectedItem)
  177.   {
  178.     var selectedRow = 
  179.       selectedItem.getElementsByTagName("treerow")[0];
  180.     if (selectedRow)
  181.     {
  182.       var selectedCell = 
  183.         selectedRow.getElementsByTagName("treecell")[0];
  184.       if (selectedCell)
  185.         URI = selectedCell.getAttribute("label");
  186.     }
  187.   }
  188.  
  189.   return URI;
  190. }
  191.  
  192. //---------------------------------------------------------------------------
  193. //   Interface to P3P backend
  194. //---------------------------------------------------------------------------
  195. var gPolicyViewer = null; // one policy viewer per page info window
  196. var gPrivacyTabInfo = null;
  197.  
  198. function onMachineReadable()
  199. {
  200.   if (!gPolicyViewer) {
  201.     gPolicyViewer = new nsPolicyViewer(gTopDoc);
  202.   }
  203.   gPolicyViewer.load(getSelectedURI(), LOAD_SUMMARY);
  204. }
  205.  
  206. function onHumanReadable()
  207. {
  208.   if (!gPolicyViewer) {
  209.     gPolicyViewer = new nsPolicyViewer(gTopDoc);
  210.   }
  211.   gPolicyViewer.load(getSelectedURI(), LOAD_POLICY);
  212.  
  213. }
  214.  
  215. function onOptInOptOut()
  216. {
  217.   if (!gPolicyViewer) {
  218.     gPolicyViewer = new nsPolicyViewer(gTopDoc);
  219.   }
  220.   gPolicyViewer.load(getSelectedURI(), LOAD_OPTIONS);
  221.  
  222. }
  223.  
  224. function finalizePolicyViewer()
  225. {
  226.   if (gPolicyViewer)
  227.     gPolicyViewer.finalize();
  228. }
  229.  
  230. addEventListener("unload", finalizePolicyViewer, false);
  231.  
  232.